﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:PerformancePrjEntry
    /// </summary>
    public partial class PerformancePrjEntry
    {
        public PerformancePrjEntry()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal FPerformancePrjEntryID, string FPerformanceFileClsCd, decimal FPerformancePrjID, string FEntityNo, string FInsEmpNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from dbo.t_PerformancePrjEntry");
            strSql.Append(" where FPerformancePrjEntryID=@FPerformancePrjEntryID and FPerformanceFileClsCd=@FPerformanceFileClsCd and FPerformancePrjID=@FPerformancePrjID and FEntityNo=@FEntityNo and FInsEmpNo=@FInsEmpNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPerformancePrjEntryID", SqlDbType.Decimal,13),
					new SqlParameter("@FPerformanceFileClsCd", SqlDbType.NVarChar,3),
					new SqlParameter("@FPerformancePrjID", SqlDbType.Decimal,13),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = FPerformancePrjEntryID;
            parameters[1].Value = FPerformanceFileClsCd;
            parameters[2].Value = FPerformancePrjID;
            parameters[3].Value = FEntityNo;
            parameters[4].Value = FInsEmpNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public decimal Add(ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_PerformancePrjEntry(");
            strSql.Append("FPerformancePrjID,FAttachSvrFileName,FAttachOldFileName,FAttachDesc,FAttachFileExt,FEntityNo,FInsEmpNo,FInsDate,FInsIP,FUpdEmpNo,FUpdDate,FUpdIP,FPerformanceFileClsCd,FIsPublic)");
            strSql.Append(" values (");
            strSql.Append("@FPerformancePrjID,@FAttachSvrFileName,@FAttachOldFileName,@FAttachDesc,@FAttachFileExt,@FEntityNo,@FInsEmpNo,@FInsDate,@FInsIP,@FUpdEmpNo,@FUpdDate,@FUpdIP,@FPerformanceFileClsCd,@FIsPublic)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@FPerformancePrjID", SqlDbType.Decimal,13),
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,200),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FPerformanceFileClsCd", SqlDbType.NVarChar,3),
					new SqlParameter("@FIsPublic", SqlDbType.NVarChar,1)};
            parameters[0].Value = model.FPerformancePrjID;
            parameters[1].Value = model.FAttachSvrFileName;
            parameters[2].Value = model.FAttachOldFileName;
            parameters[3].Value = model.FAttachDesc;
            parameters[4].Value = model.FAttachFileExt;
            parameters[5].Value = model.FEntityNo;
            parameters[6].Value = model.FInsEmpNo;
            parameters[7].Value = model.FInsDate;
            parameters[8].Value = model.FInsIP;
            parameters[9].Value = model.FUpdEmpNo;
            parameters[10].Value = model.FUpdDate;
            parameters[11].Value = model.FUpdIP;
            parameters[12].Value = model.FPerformanceFileClsCd;
            parameters[13].Value = model.FIsPublic;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToDecimal(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_PerformancePrjEntry set ");
            strSql.Append("FAttachSvrFileName=@FAttachSvrFileName,");
            strSql.Append("FAttachOldFileName=@FAttachOldFileName,");
            strSql.Append("FAttachDesc=@FAttachDesc,");
            strSql.Append("FAttachFileExt=@FAttachFileExt,");
            strSql.Append("FInsDate=@FInsDate,");
            strSql.Append("FInsIP=@FInsIP,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP,");
            strSql.Append("FIsPublic=@FIsPublic");
            strSql.Append(" where FPerformancePrjEntryID=@FPerformancePrjEntryID");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,200),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FIsPublic", SqlDbType.NVarChar,1),
					new SqlParameter("@FPerformancePrjEntryID", SqlDbType.Decimal,13),
					new SqlParameter("@FPerformancePrjID", SqlDbType.Decimal,13),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FPerformanceFileClsCd", SqlDbType.NVarChar,3)};
            parameters[0].Value = model.FAttachSvrFileName;
            parameters[1].Value = model.FAttachOldFileName;
            parameters[2].Value = model.FAttachDesc;
            parameters[3].Value = model.FAttachFileExt;
            parameters[4].Value = model.FInsDate;
            parameters[5].Value = model.FInsIP;
            parameters[6].Value = model.FUpdDate;
            parameters[7].Value = model.FUpdIP;
            parameters[8].Value = model.FIsPublic;
            parameters[9].Value = model.FPerformancePrjEntryID;
            parameters[10].Value = model.FPerformancePrjID;
            parameters[11].Value = model.FEntityNo;
            parameters[12].Value = model.FInsEmpNo;
            parameters[13].Value = model.FUpdEmpNo;
            parameters[14].Value = model.FPerformanceFileClsCd;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(decimal FPerformancePrjEntryID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_PerformancePrjEntry ");
            strSql.Append(" where FPerformancePrjEntryID=@FPerformancePrjEntryID");
            SqlParameter[] parameters = {
					new SqlParameter("@FPerformancePrjEntryID", SqlDbType.Decimal)
			};
            parameters[0].Value = FPerformancePrjEntryID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(decimal FPerformancePrjEntryID, string FPerformanceFileClsCd, decimal FPerformancePrjID, string FEntityNo, string FInsEmpNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_PerformancePrjEntry ");
            strSql.Append(" where FPerformancePrjEntryID=@FPerformancePrjEntryID and FPerformanceFileClsCd=@FPerformanceFileClsCd and FPerformancePrjID=@FPerformancePrjID and FEntityNo=@FEntityNo and FInsEmpNo=@FInsEmpNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPerformancePrjEntryID", SqlDbType.Decimal,13),
					new SqlParameter("@FPerformanceFileClsCd", SqlDbType.NVarChar,3),
					new SqlParameter("@FPerformancePrjID", SqlDbType.Decimal,13),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = FPerformancePrjEntryID;
            parameters[1].Value = FPerformanceFileClsCd;
            parameters[2].Value = FPerformancePrjID;
            parameters[3].Value = FEntityNo;
            parameters[4].Value = FInsEmpNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string FPerformancePrjEntryIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_PerformancePrjEntry ");
            strSql.Append(" where FPerformancePrjEntryID in (" + FPerformancePrjEntryIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry GetModel(decimal FPerformancePrjEntryID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FPerformancePrjEntryID,FPerformancePrjID,FAttachSvrFileName,FAttachOldFileName,FAttachDesc,FAttachFileExt,FEntityNo,FInsEmpNo,FInsDate,FInsIP,FUpdEmpNo,FUpdDate,FUpdIP,FPerformanceFileClsCd,FIsPublic from dbo.t_PerformancePrjEntry ");
            strSql.Append(" where FPerformancePrjEntryID=@FPerformancePrjEntryID");
            SqlParameter[] parameters = {
					new SqlParameter("@FPerformancePrjEntryID", SqlDbType.Decimal)
			};
            parameters[0].Value = FPerformancePrjEntryID;

            ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry model = new ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry model = new ElingOA6_Admin_DSJCJ.Model.PerformancePrjEntry();
            if (row != null)
            {
                if (row["FPerformancePrjEntryID"] != null && row["FPerformancePrjEntryID"].ToString() != "")
                {
                    model.FPerformancePrjEntryID = decimal.Parse(row["FPerformancePrjEntryID"].ToString());
                }
                if (row["FPerformancePrjID"] != null && row["FPerformancePrjID"].ToString() != "")
                {
                    model.FPerformancePrjID = decimal.Parse(row["FPerformancePrjID"].ToString());
                }
                if (row["FAttachSvrFileName"] != null)
                {
                    model.FAttachSvrFileName = row["FAttachSvrFileName"].ToString();
                }
                if (row["FAttachOldFileName"] != null)
                {
                    model.FAttachOldFileName = row["FAttachOldFileName"].ToString();
                }
                if (row["FAttachDesc"] != null)
                {
                    model.FAttachDesc = row["FAttachDesc"].ToString();
                }
                if (row["FAttachFileExt"] != null)
                {
                    model.FAttachFileExt = row["FAttachFileExt"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmpNo"] != null)
                {
                    model.FUpdEmpNo = row["FUpdEmpNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row["FPerformanceFileClsCd"] != null)
                {
                    model.FPerformanceFileClsCd = row["FPerformanceFileClsCd"].ToString();
                }
                if (row["FIsPublic"] != null)
                {
                    model.FIsPublic = row["FIsPublic"].ToString();
                }
                if (row.Table.Columns.Contains("FPerformanceFileClsName"))
                {
                    if (row["FPerformanceFileClsName"] != null)
                    {
                        model.FPerformanceFileClsName = row["FPerformanceFileClsName"].ToString();
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FPerformanceFileClsName,FPerformancePrjEntryID,FPerformancePrjID,FAttachSvrFileName,FAttachOldFileName,FAttachDesc,FAttachFileExt,FEntityNo,FInsEmpNo,FInsDate,FInsIP,FUpdEmpNo,FUpdDate,FUpdIP,FPerformanceFileClsCd,FIsPublic ");
            strSql.Append(" FROM v_PerformancePrjEntry ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FPerformancePrjEntryID,FPerformancePrjID,FAttachSvrFileName,FAttachOldFileName,FAttachDesc,FAttachFileExt,FEntityNo,FInsEmpNo,FInsDate,FInsIP,FUpdEmpNo,FUpdDate,FUpdIP,FPerformanceFileClsCd,FIsPublic ");
            strSql.Append(" FROM dbo.t_PerformancePrjEntry ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM dbo.t_PerformancePrjEntry ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FPerformancePrjEntryID desc");
            }
            strSql.Append(")AS Row, T.*  from dbo.t_PerformancePrjEntry T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_PerformancePrjEntry";
            parameters[1].Value = "FPerformancePrjEntryID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

